package com.example.service;

import com.example.entity.Family;
import com.example.mapper.FamilyMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class FamilyService {
    private final FamilyMapper familyMapper;

    public FamilyService(FamilyMapper familyMapper) {
        this.familyMapper = familyMapper;
    }

    public List<Family> getAllFamilies() {
        return familyMapper.selectAll();
    }

    @Transactional
    public boolean deleteFamily(Integer id) {
        return familyMapper.deleteById(id) > 0;
    }

    @Transactional
    public boolean addFamily(Family family) {
        return familyMapper.insert(family) > 0;
    }

    public Family getFamilyById(Integer id) {
        return familyMapper.selectById(id);
    }

    @Transactional
    public boolean updateFamily(Family family) {
        return familyMapper.update(family) > 0;
    }

    public List<Family> getFamilyByAdminUserId(Integer adminUserId) {
        return familyMapper.selectByAdminUserId(adminUserId);
    }
} 